from SocketServer import BaseRequestHandler, TCPServer
from math import sqrt

import struct

class EchoTCPHandler(BaseRequestHandler):
  def handle(self):
    print("Accepted connection")

    num = struct.unpack("!i", self.request.recv(4))[0] #int(self.request.recv(1024))
    self.request.sendall(struct.pack("!d", sqrt(num)))# ("%f\n" % sqrt(num))

if __name__ == "__main__":
  server = TCPServer(("localhost", 9999), EchoTCPHandler)
  server.serve_forever()
